用!exchain命令可以显示FS[0]链条:
0:000> !exchain 0007ffb0: notepad!_except_handler3+0 (010075ba) CRT scope 0, filter: notepad!WinMainCRTStartup+18d (0100752a) func: notepad!WinMainCRTStartup+1a1 (0100753e) 0007ffe0: kernel32!_except_handler3+0 (7c839ad8) CRT scope 0, filter: kernel32!BaseProcessStart+29 (7c8438ea) func: kernel32!BaseProcessStart+3a (7c843900) Invalid exception stack at ffffffff
上面一个是编译器入口函数登记的异常处理器,后一个是BaseProcessStart函数登记的。当应用程序中发生未处理异常时,这两个处理器的过滤函数会调用UnhandledExceptionFilter().
对于发生在WinMainCRTStartup函数之内的异常,那么上面一个处理器会先被调用,也就是执行0100752a这个编译器根据过滤表达式所编译出的函数:
notepad!WinMainCRTStartup+0x18d: 0100752a 8b45ec mov eax,dword ptr [ebp-14h] 0100752d 8b08 mov ecx,dword ptr [eax] 0100752f 8b09 mov ecx,dword ptr [ecx] 01007531 894dd8 mov dword ptr [ebp-28h],ecx 01007534 50 push eax 01007535 51 push ecx 01007536 e88b000000 call notepad!_XcptFilter (010075c6) 0100753b 59 pop ecx 0100753c 59 pop ecx 0100753d c3 ret
尽管notepad!_XcptFilter内部有多个分支,但是大多数情况都是调用UnhandledExceptionFilter,即:
msvcrt!_XcptFilter+0x158: 77c32f06 ff750c push dword ptr [ebp+0Ch] 77c32f09 ff15c411c177 call dword ptr [msvcrt!_imp__UnhandledExceptionFilter (77c111c4)]
其实下面一个异常处理器(BaseProcessStart的)也是调用UnhandledExceptionFilter:
0:000> u 7c8438ea kernel32!BaseProcessStart+0x29: 7c8438ea 8b45ec mov eax,dword ptr [ebp-14h] 7c8438ed 8b08 mov ecx,dword ptr [eax] 7c8438ef 8b09 mov ecx,dword ptr [ecx] 7c8438f1 894de4 mov dword ptr [ebp-1Ch],ecx 7c8438f4 50 push eax 7c8438f5 e8d0060200 call kernel32!UnhandledExceptionFilter (7c863fca) 7c8438fa c3 ret
|